package cn.wp.ewallet.exchange.web.controller;

import cn.wp.common.core.Wp;
import cn.wp.common.core.dto.WpResult;
import cn.wp.common.core.model.WpPage;
import cn.wp.ewallet.common.service.PubItemDictService;
import cn.wp.ewallet.wallet.model.entity.UserPublishDo;
import cn.wp.ewallet.wallet.service.UserPublishService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping(Wp.WebContext + "/ewallet/publish")
@Api(tags = "A-用户发布")
public class UserPublishController {

    @Autowired
    private PubItemDictService pubItemDictService;
    @Autowired
    private UserPublishService userPublishService;

    /**
     * 获取系统参考价格
     *
     * @return
     */
    @GetMapping("/systemPrice")
    @ApiOperation(value = "获取系统参考价格", tags = "")
    public WpResult getSystemPrice() {
        String systemPrice = pubItemDictService.getPubItemDictByCode("1006", "system_price").getItemValue();
        return WpResult.suc(systemPrice);
    }


    /**
     * 创建发布
     *
     * @param userPublish
     * @return
     */
    @PostMapping("/pub")
    @ApiOperation(value = "创建发布", tags = "")
    public WpResult pub(@ApiParam(required = true) UserPublishDo userPublish, String transPwd) {
        return userPublishService.pub(userPublish, transPwd);
    }


    /**
     * 发布列表
     *
     * @param type
     * @return
     */
    @PostMapping("/list")
    @ApiOperation(value = "获取发布信息列表", tags = "")
    public WpResult pubList(Integer type,
                            String userId,
                            @ApiParam(required = true, example = "1") Integer pageNo,
                            @ApiParam(required = true, example = "10") Integer pageSize) {
        return userPublishService.pubList(type, userId, pageNo, pageSize);
    }

    /**
     * 发布列表
     *
     * @param type
     * @return
     */
    @PostMapping("/sysList")
    @ApiOperation(value = "获取发布信息列表", tags = "")
    public WpResult sysList(Integer type,
                            String userId,
                            WpPage wpPage) {
        return userPublishService.pubList(type, userId, wpPage);
    }

    /**
     * 取消发布
     *
     * @param publishId
     * @return
     */
    @PostMapping("/depub")
    @ApiOperation(value = "取消发布", tags = "")
    public WpResult depub(@ApiParam(required = true) String publishId) {
        return userPublishService.depub(publishId);
    }

}
